package com.zkrt.upms.dto;

import com.zkrt.upms.common.constant.HJ212Constant;
import com.zkrt.upms.common.util.HJ212Util;
import lombok.Data;

@Data
public class HJ212MsgDTO {

    private String qn;
    private String st;
    private String cn;
    private String pw;
    private String mn;
    private String flag;
    private String cp;
    private String dataTime;
    private String phValue;
    private String phFlag;
    private String oValue;
    private String oFlag;
    private String swValue;
    private String swFlag;

    public String getText() {
        StringBuffer sb = new StringBuffer();
        String str = sb.append(HJ212Constant.qnKey).append("=").append(qn).append(";")
                .append(HJ212Constant.stKey).append("=").append(st).append(";")
                .append(HJ212Constant.cnKey).append("=").append(cn).append(";")
                .append(HJ212Constant.pwKey).append("=").append(pw).append(";")
                .append(HJ212Constant.mnKey).append("=").append(mn).append(";")
                .append(HJ212Constant.flagKey).append("=").append(flag).append(";")
                .append(HJ212Constant.cpKey).append("=").append("&&")
                .append(HJ212Constant.dtKey).append("=").append(dataTime).append(";")
                .append(HJ212Constant.ovKey).append("=").append(oValue).append(",")
                .append(HJ212Constant.ofKey).append("=").append(oFlag).append(";")
                .append(HJ212Constant.swvKey).append("=").append(swValue).append(",")
                .append(HJ212Constant.swfKey).append("=").append(swFlag).append(";")
                .append(HJ212Constant.phvKey).append("=").append(phValue).append(",")
                .append(HJ212Constant.phfKey).append("=").append(phFlag)
                .append("&&").toString();
        String crc = HJ212Util.getCRC16(str);
        int crcLength = crc.length();
        if (crcLength < 4) {
            for (int i = crcLength; i < 4; i++) {
                crc = new StringBuffer("0").append(crc).toString();
            }
        }
        int length = str.length();
        String format = String.format("%04d", length);
        String s = new StringBuffer().append("##").append(format).append(str).append(crc).append("\r\n").toString();
        return s;
    }

}
